﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Basicas;
using MySql.Data.MySqlClient;
using Basicas.Utils;
using System.Data;

namespace ProjetoJornada_DAL.Repositorio
{
    public class RepResponsavel
    {
        private DAO dao;

        public RepResponsavel()
        {
            this.dao = DAO.Instance;
        }

        public int Inserir(Responsavel responsavel)
        {

            String storeProcedure = "sp_Responsavel_Inserir";

            try
            {
                MySqlParameter[] parametros = new MySqlParameter[7];

                parametros[0] = new MySqlParameter();
                parametros[0].ParameterName = @"cpfIn";
                parametros[0].Value = responsavel.Cpf;
                parametros[0].MySqlDbType = MySqlDbType.String;
                
                parametros[1] = new MySqlParameter();
                parametros[1].ParameterName = @"CargoIn";
                parametros[1].Value = responsavel.Cargo;
                parametros[1].MySqlDbType = MySqlDbType.Int32;

                parametros[2] = new MySqlParameter();
                parametros[2].ParameterName = @"NomeIn";
                parametros[2].Value = responsavel.Nome;
                parametros[2].MySqlDbType = MySqlDbType.String;

                parametros[3] = new MySqlParameter();
                parametros[3].ParameterName = @"TelefoneIn";
                parametros[3].Value = responsavel.Telefone;
                parametros[3].MySqlDbType = MySqlDbType.String;

                parametros[4] = new MySqlParameter();
                parametros[4].ParameterName = @"CelularIn";
                parametros[4].Value = responsavel.Celular;
                parametros[4].MySqlDbType = MySqlDbType.String;

                parametros[5] = new MySqlParameter();
                parametros[5].ParameterName = @"EmailIn";
                parametros[5].Value = responsavel.Email;
                parametros[5].MySqlDbType = MySqlDbType.String;

                parametros[6] = new MySqlParameter();
                parametros[6].ParameterName = @"Result";
                parametros[6].MySqlDbType = MySqlDbType.Int32;
                parametros[6].Direction = ParameterDirection.Output;


                int idMembro = (int)dao.ExecutaFuncao(parametros, storeProcedure);

                return idMembro;

            }
            catch (Exception ex)
            {
                Auxiliar.GravaLog(ex.Message, "inserirResponsavel - Repositorio");
                throw ex;
            }

        }

    }
}